//
//  PopoverPresentationController.swift
//  weibo1
//
//  Created by changhongliang on 2017/7/24.
//  Copyright © 2017年 richinfo. All rights reserved.
//

import UIKit

class PopoverPresentationController: UIPresentationController {
    
    override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) {
        super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
    }
    
    override func containerViewWillLayoutSubviews() {
        containerView?.insertSubview(coverView, at: 0)
        coverView.frame = (containerView?.frame)!
        presentedView?.frame = CGRect(x: 100, y: 64, width: 200, height: 200)
    }
    
    func close(){
        presentedViewController.dismiss(animated: true, completion: nil)
    }
    
    lazy var coverView:UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        let tap = UITapGestureRecognizer(target: self, action: #selector(PopoverPresentationController.close))
        view.addGestureRecognizer(tap)
        return view
    }()
    

}
